Vue.component("upload-images", {
  template: `<el-upload class="upload-demo" :show-file-list="false" accept="image/*" drag :on-change="upload" :auto-upload="false" action="" multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
            只能上传jpg/png文件
            <el-slider :min="1" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
        </div>
    </el-upload>
    `,
  props: ["data", "id"],
  data() {
    return {
      quality: 100,
    };
  },
  mounted() {},
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      // console.log(raw);
      // console.log( raw.size / 1024 / 1024);
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          const isJPGorPNG =
            file.type === "image/jpeg" || file.type === "image/png";
          const isLt500K = file.size / 1024 / 1024 < 10;
          if (!isJPGorPNG) {
            that.$message({
              message: "上传头像图片只能是 JPG/PNG 格式!",
              type: "warning",
            });
            return false;
          }
          if (!isLt500K) {
            that.$message({
              message: "上传图片大小不能超过 10MB! 可压缩后上传",
              type: "warning",
            });
            return false;
          }
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            $.ajax({
              headers: requestHeaders("JSON"),
              url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
              type: "POST",
              data: JSON.stringify({
                Data: e.target.result,
                DataLength: file.size,
                FileName: file.name,
              }),
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              success: function (Result) {
                if (Result.Status == "success") {
                  that.$message.success("上传成功");
                  that.data.push({
                    Base64: e.target.result,
                    Picture_URL: Result.FileName,
                    Picture_Type: 0,
                    id: that.id,
                  });
                } else {
                  that.$message.error("上传失败");
                }
              },
              error: function () {
                that.$message.error("图片过大，可尝试压缩");
              },
              dataType: "json",
            });
          };
        },
      });
    },
  },
});
Vue.component("yl-upload1", {
  template: `<div>
    <div class="preview" style="width:100px;height:100px" v-if="Picture_URL">
        <el-image class="el-upload-list__item-thumbnail" style="width: 100px; height: 100px" :src="base64?Picture_URL:base + Picture_URL" fit="contain"></el-image>
        <span class="el-upload-list__item-actions" style="width:100px;height:100px">
            <span @click="handlePictureCardPreview(base64?Picture_URL:base + Picture_URL)"><i class="el-icon-zoom-in"></i></span>
            <span @click="handleRemove"><i class="el-icon-delete"></i></span>
        </span>
    </div>
    <el-upload id="group" :disabled="loading" v-else class="upload-demo" :show-file-list="false" :on-change="upload"
        list-type="picture-card" action="" accept="image/*" :auto-upload="false">
        <i slot="default" :class="loading?'el-icon-loading':'el-icon-plus'"></i>
        <div v-if="!unslider" class="el-upload__tip" slot="tip">
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
            <el-slider :min="1" style="width:148px" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
        </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <el-image width="100%" fit="contain" :src="dialogImageUrl">
    </el-dialog></div>`,
  props: {
    value: {
      type: String,
      default: "",
    },
    base: {
      type: String,
      default: "",
    },
    base64: {
      type: Boolean,
      default: false,
    },
    unslider: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      Picture_URL: this.value,
      loading: false,
      dialogVisible: false,
      dialogImageUrl: "",
      quality: 100,
    };
  },
  watch: {
    value(newVal) {
      this.Picture_URL = newVal;
    },
    Picture_URL(newVal) {
      this.$emit("input", newVal);
    },
  },
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          that.loading = true;
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            if (!that.base64) {
              $.ajax({
                headers: requestHeaders("JSON"),
                url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
                type: "POST",
                data: JSON.stringify({
                  Data: e.target.result,
                  DataLength: file.size,
                  FileName: file.name,
                }),
                success: function (Result) {
                  if (Result.Status == "success") {
                    that.Picture_URL = Result.FileName;
                    that.$message.success("上传成功");
                  } else {
                    that.$message.error("上传失败");
                  }
                },
                complete: function (XMLHttpRequest) {
                  that.loading = false;
                  requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
              });
            } else {
              that.Picture_URL = e.target.result;
              that.loading = false;
            }
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },
    handlePictureCardPreview(Val) {
      this.dialogVisible = true;
      this.dialogImageUrl = Val;
    },
    handleRemove() {
      this.Picture_URL = "";
    },
  },
});
new Vue({
  el: "#app",
  data() {
    return {
      upLoadFilesList: new Array(new Array()),
      UserID: decodeURI($.cookie("use")),
      jcfileList: [],
      DfileList: [],
      cfileList: [],
      ggfileList: [],
      fmfileList: [],
      dialogUrl: "",
      dialogVsble: false,
      business_article_specifications: [],
      dj: {},
      fh: {},
      dh: {},
      wk: {},
      category: [], //类别
      is_Article_Type: "", // 包装信息
      is_Unit_Price: "",
      is_JDCOM_Unit_Price: "",
      bzdw: [
        {
          value: "箱",
          label: "箱",
        },
        {
          value: "瓶",
          label: "瓶",
        },
        {
          value: "袋",
          label: "袋",
        },
      ],
      article_info: [
        {
          value: "预包装",
          label: "预包装",
        },
      ], //包装信息
      VarietyID: "",
      GradeID: "",
      iJSONArray_Variety: [],
      iJSONArray_VarietyGrade: [],
      form: {
        ClassifyJSON: "",
        Article_Name: "", //商品名称

        Brand_SerialNumber: "", //商品品牌
        Category_SerialNumber: "", //商品类别
      },
      rules: {
        Article_Name: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
        ],
        Brand_SerialNumber: [
          { required: true, message: "请选择商品品牌", trigger: "change" },
        ],
        // Unit_Price: [{ required: true, message: '请输入商品吊牌价', trigger: 'change' }],
        Specifications_Name: [
          { required: true, message: "请输入规格名称", trigger: "blur" },
        ],
        // SKU_Quantity: [{ required: true, message: '请输入SKU数量', trigger: 'blur' }]
      },
      item: [],
      Main_Image: [],
      Detail_Image: [],
      brand: [], //品牌
      unit: [], //单位
      supplier: [], //供应商
      activity: [], //活动
      classify: [],
      // business_article_classify: [],
      defaultProps: {
        children: "Children",
        label: "Classify_Name",
        value: "Classify_SerialNumber",
        multiple: true,
      },
      loading: false,
      isMainSort: false, //主图排序
      isDetailSort: false, //详情图排序
      MainSortable: null, //主图拖拽
      DetailSortable: null, //详情图拖拽
      activeName: 0, //图片
      business_article_group: [],
    };
  },
  mounted() {
    this.getbrandList();
    this.getVarietyList();
    // this.dhcph();
    this.getcategoryList();
    // this.getVarietyList();
    // this.getData();
    this.sortable(
      this,
      "#Main_Image",
      ".preview",
      this.Main_Image,
      "MainSortable"
    );
    this.sortable(
      this,
      "#Detail_Image",
      ".preview",
      this.Detail_Image,
      "DetailSortable"
    );
    this.business_article_group.push({
      Specification_Group_Name: "规格",
      Picture_URL: "",
      Children: {
        business_article_group_detail: [
          {
            id: createUniqueString(),
            Specification_Group_Detail_Name: "",
          },
        ],
      },
    });
    this.business_article_specifications.push({
      Specifications_Name: "",
      Unit_Price: "", //吊牌价
      SKU_Quantity: "", //SKU数量
      Size: "",
      Picture_URL: "",
    });
  },
  watch: {
    isMainSort(val) {
      this.MainSortable.option("disabled", !val);
    },
    isDetailSort(val) {
      this.DetailSortable.option("disabled", !val);
    },
    "form.Unit_Price": function (val) {
      if (this.form.Unify_Unit_Price == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = val;
        });
      }
    },
    "form.Unify_Unit_Price": function (val) {
      if (val == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = this.form.Unit_Price;
        });
      }
    },
  },
  computed: {
    business_supplier_article() {
      let business_supplier_article = [];
      this.form.Children.business_article_specifications.forEach((item) => {
        item.Other.filter((i) => i.Supplier_SerialNumber).forEach((ite) => {
          business_supplier_article.push({
            Supplier_Article_SerialNumber: "",
            Article_Name: this.form.Article_Name,
            Specifications_Name: item.Specifications_Name,
            Brand_SerialNumber: this.form.Brand_SerialNumber,
            Supplier_SerialNumber: ite.Supplier_SerialNumber,
            Article_SerialNumber: "",
            Article_Specifications_SerialNumber: "",
            Shelf: "1",
            Sales_Unit_Price: ite.Sales_Unit_Price,
            Purchase_Unit_Price: ite.Purchase_Unit_Price,
            Quantity: ite.Quantity,
            Pionts: ite.Pionts,
            Deduction_Type: ite.Deduction_Type,
            Deduction_Limit: ite.Deduction_Limit,
            Activity: ite.Activity,
          });
        });
      });
      return business_supplier_article;
    },
    // showFileList: function () {
    //   return function (url) {
    //     return url ? [url] : [];
    //   };
    // },
  },
  methods: {
    ahandleRemove(index) {
      console.log(index);
      // return;
      this.upLoadFilesList[index] = new Array();
      this.business_article_specifications[index].Picture_URL = "";
      this.$set(this, "upLoadFilesList", [...this.upLoadFilesList]);
      console.log(this.upLoadFilesList);
    },
    ahandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    showFileList: function (index) {
      // return function (url) {
      //   return url ? [url] : [];
      // };
      console.log("index", index, this.upLoadFilesList[index]);

      return this.upLoadFilesList[index];
    },
    ahandleBeforeUpload(file, index) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      console.log(file, index);

      // return;
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          Add: 1,
          // 可以添加其他属性，如上传状态等
        };
        this.upLoadFilesList[index] = new Array();
        console.log(this.upLoadFilesList[index]);
        this.upLoadFilesList[index].push(newFile);
        this.$set(this, "upLoadFilesList", [...this.upLoadFilesList]);

        console.log(888, this.upLoadFilesList);
        console.log(this.upLoadFilesList[index]);

        // console.log(newFile);
        // return;
        const _this = this;
        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(this.upLoadFilesList[index]), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
            console.log(_this.upLoadFilesList[index]);

            let base64Image = _this.upLoadFilesList[index][0].url;
            let dataIndex = base64Image.indexOf("data:");
            let base64Index = base64Image.indexOf(";base64,");
            let substring = base64Image.substring(dataIndex + 5, base64Index);
            let ls_split = substring.split("/");
            _this.business_article_specifications[index].Picture_URL =
              _this.upLoadFilesList[index][0].uid + "." + ls_split[1];

            console.log(111, _this.business_article_specifications[index]);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      // console.log(this.fmfileList);

      // 返回false以阻止自动上传
      return false;
    },
    //查询企业信息和个人信息
    // dhcph() {
    //   console.log(this.UserID);
    //   let Arg_UserID = this.UserID;
    //   const _this = this;
    //   $.ajax({
    //     // headers: requestHeaders(),
    //     url: "https://service.kdddy.cn/donghuiForRequest/selectByData/selectEnterpriseID",
    //     type: "get",
    //     data: {
    //       Data: Arg_UserID,
    //     },
    //     success: function (Result) {
    //       console.log(Result.Data[0].Enterprise_Info_SerialNumber);
    //       _this.getbrandList(Result.Data[0].Enterprise_Info_SerialNumber);
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
    //     },
    //     dataType: "json",
    //   });
    // },
    handleRemove(file, fileList) {
      // this.fileList = [];
      this.fmfileList.splice(0, 1);
    },
    //删除时保留一个框

    jchandleRemove(file, fileList) {
      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "jcfileList", arr);
    },
    DhandleRemove(file, fileList) {
      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "DfileList", arr);
    },
    zhandleRemove(file, fileList) {
      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "cfileList", arr);
    },
    jcDhandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    jchandleBeforeUpload(file) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          // 可以添加其他属性，如上传状态等
        };
        this.jcfileList.push(newFile);
        let arrjc = this.jcfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "jc_" + item.uid;
            console.log(item);
            return item;
          }
        });
        console.log("=====", arrjc);
        // for (let i = 0; i < this.jcfileList.length; i++) {
        //   this.jcfileList[i].uid = "jc_" + this.jcfileList[i].uid;
        // }
        // console.log(this.jcfileList);
        // return;
        $.ajax({
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrjc), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      console.log(this.jcfileList);

      // 返回false以阻止自动上传
      return false;
    },
    DhandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    DhandleBeforeUpload(file) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          // 可以添加其他属性，如上传状态等
        };
        this.DfileList.push(newFile);
        let arrjc = this.DfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "D_" + item.uid;
            console.log(item);
            return item;
          }
          // return item;
        });
        console.log("=====", arrjc);
        // for (let i = 0; i < this.DfileList.length; i++) {
        //   this.DfileList[i].uid = "D_" + this.DfileList[i].uid;
        // }
        // console.log(this.DfileList);
        // const _this = this;
        // return;
        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrjc), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      // 返回false以阻止自动上传

      return false;
    },
    chandleBeforeUpload(file, fileList) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      console.log(file, fileList);

      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          // 可以添加其他属性，如上传状态等
        };
        this.cfileList.push(newFile);
        let arrjc = this.cfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "M_" + item.uid;
            console.log(item);
            return item;
          }
        });
        console.log("=====", arrjc);

        // for (let i = 0; i < this.cfileList.length; i++) {
        //   this.cfileList[i].uid = "M_" + this.cfileList[i].uid;
        // }

        // return;
        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          // url: "http://192.168.10.3:8083/article/articlePictureUpLoad",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrjc), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {},
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);

      // const _this = this;
      // console.log(_this.cfileList);

      // 返回false以阻止自动上传
      return false;
    },
    handleUploadForm(param) {
      console.log(param);
      let file = param.file;
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result,
          uid: file.uid, // 预览URL
          // 可以添加其他属性，如上传状态等
        };
        this.ggfileList.push(newFile);
        this.$set(
          this.business_article_specifications[param.data],
          "Picture_URL",
          newFile
        );
      };
      reader.readAsDataURL(file);
    },
    ahandleBeforeRemove(file, fileList) {
      const index = this.business_article_specifications.findIndex(
        (item) => item.Picture_URL && item.Picture_URL.uid == file.uid
      );
      if (index > -1) {
        this.$set(
          this.business_article_specifications[index],
          "Picture_URL",
          ""
        );
      }
    },

    ahandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
      // fileList.push(file);
      this.pfile = file;

      console.log(file);
      console.log(fileList);
    },
    chandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    handleBeforeUpload(file) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          // 可以添加其他属性，如上传状态等
        };
        this.fmfileList.push(newFile);
        for (let i = 0; i < this.fmfileList.length; i++) {
          this.fmfileList[i].uid = "C_" + this.fmfileList[i].uid;
        }
        console.log(this.fmfileList);

        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(this.fmfileList), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      // console.log(this.fmfileList);

      // 返回false以阻止自动上传
      return false;
    },
    handleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
      fileList.push(file);
      this.pfile = file;

      console.log(file);
      console.log(fileList);
    },
    handRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePcPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    tpsc(file, fileList) {
      console.log(file, fileList);
    },
    submitForm() {
      let Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        data: {
          Data: "enterprise_info", //表名
          Condition:
            "Enterprise_Info_SerialNumber = '" +
            Enterprise_Info_SerialNumber +
            "'",
        },
        success: function (Result) {
          console.log(Result);
          // if (Result[0].Need_Review == "0") {
          sessionStorage.setItem("Need_Review", Result[0].Need_Review);
          // }
          _this.sub();
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    sub() {
      console.log(this.business_article_specifications);

      if (
        this.business_article_specifications.length == 1 &&
        this.business_article_specifications[0].Picture_URL == ""
      ) {
        this.$message({
          message: "请您至少上传一个规格",
          type: "warning",
        });
        return;
      }
      this.business_article_specifications.forEach((i) => {
        i.Children = {
          business_article_log:[{
            Row_Status:'0'
          }]
        };
      });
      let Need_Review = sessionStorage.getItem("Need_Review");
      console.log(Need_Review);
      if (Need_Review == "1") {
        this.business_article_specifications.forEach((i) => {
          console.log(i);
          i.Row_Status = "1";
        });
      }
      console.log(this.business_article_specifications);

      // console.log(formName);
      console.log(this.form);

      const _this = this;
      console.log(_this.dj);
      console.log(_this.fh);
      console.log(_this.dh);
      console.log(_this.wk);

      // 校验收款方式相关逻辑
      const paymentNodes = [_this.dj, _this.fh, _this.dh, _this.wk];

      // 后续代码中添加调试输出
      console.log(_this.dj.Excepted_Days);
      console.log(_this.fh.Excepted_Days);
      console.log(_this.dh.Excepted_Days);
      console.log(_this.wk.Excepted_Days);

      // _this.form.GradeID = _this.GradeID;
      _this.form.Article_Type = _this.is_Article_Type;
      for (let i = 0; i < _this.iJSONArray_Variety.length; i++) {
        if (_this.VarietyID == _this.iJSONArray_Variety[i].VarietyID) {
          console.log(_this.iJSONArray_Variety[i].VarietyName, "----------");
          _this.form.VarietyName = _this.iJSONArray_Variety[i].VarietyName;
        }
      }

      for (let i = 0; i < _this.iJSONArray_VarietyGrade.length; i++) {
        if (_this.GradeID == _this.iJSONArray_VarietyGrade[i].GradeID) {
          console.log(_this.iJSONArray_VarietyGrade[i].GradeName, "*********");
          _this.form.GradeName = _this.iJSONArray_VarietyGrade[i].GradeName;
        }
      }

      console.log(this.form);
      //付款节点
      _this.dj.Node_Name = "定金";
      _this.dj.Payment_Ratio = _this.dj.dje;
      _this.dj.Excepted_Days =
        _this.dj.djs !== undefined && _this.dj.djs !== ""
          ? _this.dj.djs
          : _this.dj.Excepted_Days;
      _this.dj.Actual_Payment = "0";
      _this.dj.Payment_Status = "待付款";
      console.log(_this.dj, "_this.dj");
      _this.fh.Node_Name = "发货";
      _this.fh.Payment_Ratio = _this.fh.fhe;
      _this.fh.Excepted_Days =
        _this.fh.fhs !== undefined && _this.fh.fhs !== ""
          ? _this.fh.fhs
          : _this.fh.Excepted_Days;
      _this.fh.Actual_Payment = "0";
      _this.fh.Payment_Status = "待付款";
      console.log(_this.fh, "_this.fh");
      _this.dh.Node_Name = "到货";
      _this.dh.Payment_Ratio = _this.dh.dhe;
      _this.dh.Excepted_Days =
        _this.dh.dhs !== undefined && _this.dh.dhs !== ""
          ? _this.dh.dhs
          : _this.dh.Excepted_Days;
      _this.dh.Actual_Payment = "0";
      _this.dh.Payment_Status = "待付款";
      console.log(_this.dh, "_this.dh");
      _this.wk.Node_Name = "尾款";
      _this.wk.Payment_Ratio = _this.wk.wke;
      _this.wk.Excepted_Days =
        _this.wk.wks !== undefined && _this.wk.wks !== ""
          ? _this.wk.wks
          : _this.wk.Excepted_Days;
      _this.wk.Actual_Payment = "0";
      _this.wk.Payment_Status = "待付款";
      let lJSONArray_fkzq = new Array();
      lJSONArray_fkzq.push(_this.dj, _this.fh, _this.dh, _this.wk);
      console.log(lJSONArray_fkzq);

      let totalPaymentRatio = 0; //总和
      let definedCount = 0; //计数
      for (let i = 0; i < lJSONArray_fkzq.length; i++) {
        console.log(definedCount);

        if (lJSONArray_fkzq[i].Payment_Ratio !== undefined) {
          totalPaymentRatio += parseInt(lJSONArray_fkzq[i].Payment_Ratio);
          definedCount++;
        }
      }
      console.log(definedCount, "jishu");
      console.log(totalPaymentRatio);

      console.log(_this.fmfileList);
      console.log("gg", _this.ggfileList);
      console.log(_this.cfileList);
      console.log(_this.DfileList);
      console.log(_this.jcfileList);

      // 处理文件列表的公共逻辑
      function processFileList(fileList, targetObject, index = null) {
        if (fileList.length > 0) {
          let base64Image = fileList[0].url;
          let dataIndex = base64Image.indexOf("data:");
          let base64Index = base64Image.indexOf(";base64,");
          let substring = base64Image.substring(dataIndex + 5, base64Index);
          let fileType = substring.split("/")[1];
          let originalUid = fileList[0].uid;
          let uid;

          // 检查原始 uid 是否已经包含了文件扩展名
          if (originalUid.endsWith(`.${fileType}`)) {
            uid = originalUid;
          } else {
            uid = originalUid + "." + fileType;
          }

          fileList[0].uid = uid; // 设置 uid

          if (targetObject && index !== null) {
            targetObject[index].Picture_URL = uid; // 设定 Picture_URL
          }
          console.log(
            `${
              targetObject
                ? "在处理" + targetObject[index].Node_Name
                : "fmfileList"
            }: ${uid}`
          );
        }
      }

      // 检查并处理不同的文件列表
      processFileList(_this.fmfileList);
      processFileList(
        _this.ggfileList,
        _this.business_article_specifications,
        0
      );

      // 处理 cfileList
      handleFileList(_this.cfileList, "cfileList");
      function handleFileList(list, listName) {
        console.log(
          `${listName} 元素类型检查：`,
          list.map((item) => typeof item)
        );
        return list.map((item) => {
          if (typeof item === "object" && item.url) {
            let base64Image = item.url;
            let dataIndex = base64Image.indexOf("data:");
            let base64Index = base64Image.indexOf(";base64,");
            let substring = base64Image.substring(dataIndex + 5, base64Index);
            item.Picture_URL = item.uid + "." + substring.split("/")[1];
          } else {
            console.warn(`${listName} 中存在非对象元素：`, item);
          }
          return item;
        });
      }

      // 处理 DfileList
      handleFileList(_this.DfileList, "DfileList");

      // 处理 jcfileList
      let jcArr = handleFileList(_this.jcfileList, "jcfileList");

      // 合并所有处理后的图片
      let pic = [..._this.cfileList, ..._this.DfileList, ...jcArr];
      console.log(pic);

      console.log(this.form);
      console.log(this.form.Article_Name);
      if (this.form.Article_Name == "") {
        this.$message({
          message: "请输入商品名称",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.VarietyID == "") {
        this.$message({
          message: "请选择品种",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.GradeID == "") {
        this.$message({
          message: "请选择等级",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.form.Brand_SerialNumber == "") {
        this.$message({
          message: "请选择商品品牌，如为空请先去维护品牌信息",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.form.Category_SerialNumber == "") {
        this.$message({
          message: "请选择商品类型",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.is_Article_Type == "") {
        this.$message({
          message: "请选择商品包装信息",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (this.fmfileList.length == 0) {
        this.$message({
          message: "您还未上传商品封面图片",
          type: "warning",
        });
        // 新增 return 语句，终止函数执行
        return;
      } else if (true) {
        let a = 0;
        lJSONArray_fkzq.forEach((element) => {
          if (element.Payment_Ratio == undefined) {
            a = a + 1;
          }
        });
        console.log(a);
        if (a == 4) {
          this.$message.error("请您输入收款方式");
          // 新增 return 语句，终止函数执行
          return;
        }
        // else {
        let totalRatio = 0;
        let hasNonNullRatio = false;
        let isValid = true; // 用于标记是否所有校验通过
        // 检查总和是否超过100
        if (totalPaymentRatio > 100) {
          // console.error("支付比例的总和不能超过100");
          this.$message.error("支付比例的总和不能超过100");
          return;
        } else if (definedCount === 1 && totalPaymentRatio < 100) {
          this.$message.error("只有一个支付比例时，支付比例不能低于100");
          return;
        } else if (definedCount !== 1 && totalPaymentRatio < 100) {
          this.$message.error("支付比例的总和不能低于超过100");
          return;
        }
      }
      lJSONArray_fkzq.forEach((element) => {
        console.log(element);
        if (element.Payment_Ratio == 0) {
          element.Payment_Ratio = "";
        }
        if (element.Payment_Ratio == undefined) {
          element.Payment_Ratio = "";
        }
        if (
          element.Payment_Ratio !== undefined &&
          element.Excepted_Days == undefined
        ) {
          element.Excepted_Days = 0;
        }
      });
      console.log(lJSONArray_fkzq);
      // return;
      console.log(this.fmfileList, "封面图片");
      console.log(lJSONArray_fkzq);
      // lJSONArray_fkzq.forEach((element) => {
      //   element.Payment_Ratio = parseInt(element.Payment_Ratio);
      // });
      console.log(lJSONArray_fkzq);

      let lJSONObject_base_ArticlePaymentDetails = new Object();
      lJSONObject_base_ArticlePaymentDetails.base_ArticlePaymentDetails =
        lJSONArray_fkzq; //换表

      lJSONObject_base_ArticlePaymentDetails.business_article_pic = pic;

      lJSONObject_base_ArticlePaymentDetails.business_article_specifications =
        _this.business_article_specifications; //换表
      _this.form.Children = lJSONObject_base_ArticlePaymentDetails;
      // 再次检查 _this.fmfileList 是否为空
      if (_this.fmfileList.length > 0) {
        _this.form.Picture_URL = _this.fmfileList[0].uid;
      }
      let lArray = new Array();
      lArray.push(_this.form);
      let lJSONObject_business_article_info = new Object();
      lJSONObject_business_article_info.business_article_info = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Add = lJSONObject_business_article_info;
      console.log(lJSONObject_DataSet, "lJSONObject_DataSet");
      // return;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message.success("提交成功");
            window.history.go(-1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
      // }
      // }
    },
    getcategoryList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "business_category",
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result, "--------------");

          _this.category = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getbrandList() {
      let Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "business_brand",
          Condition:
            "Row_Status='0' And Enterprise_Number='" +
            Enterprise_Info_SerialNumber +
            "'",
        },
        success: function (Result) {
          console.log(Result, "--------------");
          _this.brand = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    // getbrandList() {
    //   const _this = this;
    //   $.ajax({
    //     headers: requestHeaders(),
    //     // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
    //     url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
    //     type: "POST",
    //     data: {
    //       Data: "business_brand",
    //       Condition: "Row_Status='0'",
    //     },
    //     success: function (Result) {
    //       console.log(Result, "--------------");

    //       _this.brand = Result;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
    //     },
    //     dataType: "json",
    //   });
    // },
    getVarietyList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "base_EdibleMushroomVariety",
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result, "--------------");

          _this.iJSONArray_Variety = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    handleChange(value) {
      console.log(value, "value");

      // return;
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "base_EdibleMushroomGrade",
          Condition: "Row_Status='0' AND VarietyID='" + _this.VarietyID + "'",
        },
        success: function (Result) {
          // _this.tableData = Result.Rows;
          _this.iJSONArray_VarietyGrade = new Array(); //清空数组中原有值
          _this.iJSONArray_VarietyGrade = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    // getData() {
    //   const that = this;
    //   const Condition = "Row_Status='0'";
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_brand",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.brand = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_category",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.category = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_series",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.series = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_item",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.item = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_supplier_info",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.supplier = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_article_unit",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.unit = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/getAllClassify`,
    //     type: "GET",
    //     success: function (data) {
    //       that.classify = data;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_activity",
    //       Condition: "Row_Status <> '1' AND End_Date > NOW()",
    //     },
    //     success: function (res) {
    //       that.activity = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    // },
    // submitForm(formName) {
    //   const that = this;
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       if (!that.form.Article_Code) {
    //         that
    //           .$confirm(
    //             "当前商品未录入商品编号可能会影响商品唯一性，是否继续?",
    //             "提示",
    //             {
    //               confirmButtonText: "确定",
    //               cancelButtonText: "取消",
    //               type: "warning",
    //             }
    //           )
    //           .then(() => {
    //             that.add({});
    //           })
    //           .catch(() => {});
    //       } else {
    //         that.add({
    //           business_article_config: [
    //             { Article_Code: this.form.Article_Code },
    //           ],
    //         });
    //       }
    //     } else {
    //       that.$message({
    //         message: sumberError,
    //         type: "warning",
    //       });
    //       return false;
    //     }
    //   });
    // },
    add(code) {
      const that = this;
      let obj = deepClone(that.form);
      obj.Children.business_article_group = that.business_article_group;
      this.loading = true;
      that.Main_Image.filter((i) => i.id == 0).forEach((item, index) => {
        //主图
        obj.Children.business_article_pic.push({
          Article_PicNumber: "",
          Article_SerialNumber: "",
          Picture_Type: "0",
          Picture_Order: index + 1,
          Picture_URL: item.Picture_URL,
        });
      });
      that.Detail_Image.filter((i) => i.id == 0).forEach((item, index) => {
        //详情图
        obj.Children.business_article_pic.push({
          Article_PicNumber: "",
          Article_SerialNumber: "",
          Picture_Type: "1",
          Picture_Order: index + 1,
          Picture_URL: item.Picture_URL,
        });
      });
      obj.ClassifyJSON = JSON.stringify(that.business_article_classify);
      that.business_article_classify.forEach((Array) => {
        Array.forEach((i) => {
          if (
            !obj.Children.business_article_classify.some(
              (j) => j.Classify_SerialNumber == i
            )
          ) {
            obj.Children.business_article_classify.push({
              Article_Classify_SerialNumber: "",
              Article_SerialNumber: "",
              Classify_SerialNumber: i,
              Parent_SerialNumber: Array[0],
            });
          }
        });
      });
      //提交
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Add: {
              business_article_info: [obj],
              ...code,
              base_operation_log: [
                generateLog(
                  "添加商品主数据",
                  "平台端操作",
                  "business_article_info",
                  JSON.stringify({ Add: { business_article_info: [obj] } })
                ),
              ],
            },
          }),
        },
        success: function (res) {
          if (res.Status === "success") {
            if (that.business_supplier_article.length > 0) {
              that.$message.success("商品添加成功,开始配置供应商");
              that.submitSupplier(); //提交供应商信息
            } else {
              that.loading = false;
              that.$message.success("提交成功");
              window.history.go(-1);
            }
          } else {
            that.loading = false;
            // that.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitSupplier() {
      //提交供应商
      const that = this;
      let sql = "";
      this.business_supplier_article.forEach((item) => {
        if (sql) {
          sql =
            sql +
            "\r\nOR business_article_info.Article_Name = '" +
            item.Article_Name +
            "'" +
            "\r\nAND business_article_specifications.Specifications_Name = '" +
            item.Specifications_Name +
            "'" +
            "\r\nAND business_article_info.Brand_SerialNumber = '" +
            item.Brand_SerialNumber +
            "'";
        } else {
          sql =
            " business_article_info.Article_Name = '" +
            item.Article_Name +
            "'" +
            "\r\nAND business_article_specifications.Specifications_Name = '" +
            item.Specifications_Name +
            "'" +
            "\r\nAND business_article_info.Brand_SerialNumber = '" +
            item.Brand_SerialNumber +
            "'";
        }
      });
      if (sql) {
        sql = `WHERE ${sql}`;
      }
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
        type: "POST",
        data: {
          SQLSerialNumber: "A_business_article_specifications2",
          Condition: "",
          ExtensionCondition: window.btoa(unescape(encodeURIComponent(sql))),
        },
        success: function (Result) {
          if (Result.length > 0) {
            //执行添加
            let business_supplier_article = that.business_supplier_article;
            let base_operation_log = [];
            business_supplier_article.forEach((item) => {
              let obj = Result.filter(
                (i) =>
                  i.Specifications_Name == item.Specifications_Name &&
                  i.Article_Name == item.Article_Name &&
                  i.Brand_SerialNumber == item.Brand_SerialNumber
              )[0];
              item.Article_SerialNumber = obj.Article_SerialNumber;
              item.Article_Specifications_SerialNumber =
                obj.Article_Specifications_SerialNumber;
              item.Supplier_Article_SerialNumber =
                item.Supplier_SerialNumber +
                "-" +
                obj.Article_Specifications_SerialNumber;
              //日志
              base_operation_log.push(
                generateLog(
                  "添加供应商经营商品",
                  "平台端操作",
                  "business_supplier_article",
                  JSON.stringify({ Add: { business_supplier_article: [item] } })
                )
              );
            });
            $.ajax({
              headers: requestHeaders(),
              url: `${BASE_URL2}/generalBusiness/generalSave`,
              type: "POST",
              data: {
                Data: JSON.stringify({
                  Add: { business_supplier_article, base_operation_log },
                }),
              },
              success: function (res) {
                if (res.Status === "success") {
                  //添加采购价格单
                  if (
                    business_supplier_article.filter(
                      (i) =>
                        !isNaN(i.Purchase_Unit_Price) &&
                        i.Purchase_Unit_Price > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始添加采购价格单");
                    that.submitPurchase(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) =>
                        !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                    ).length > 0
                  ) {
                    //添加销售价格单
                    that.$message.success("开始添加销售价格单");
                    that.submitSales(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) => !isNaN(i.Quantity) && i.Quantity > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始添加每日库存");
                    that.submitStock(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) =>
                        i.Pionts.length > 0 &&
                        !isNaN(i.Deduction_Limit) &&
                        i.Deduction_Limit > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始配置积分方案");
                    that.submitPointsConfig(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) => i.Activity.length > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始插入活动商品");
                    that.submitActivityArticle(business_supplier_article);
                  } else {
                    that.loading = false;
                    that.$message.success("提交成功");
                    window.history.go(-1);
                  }
                } else {
                  that.loading = false;
                  //   that.$message.error("提交失败，请稍后再试");
                }
              },
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            });
          } else {
            that.loading = false;
            that.$message.error("未知错误");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitPurchase(business_supplier_article) {
      //添加采购价格单
      const that = this;
      let business_purchase_unitprice_detail = [];
      business_supplier_article
        .filter(
          (i) => !isNaN(i.Purchase_Unit_Price) && i.Purchase_Unit_Price > 0
        )
        .forEach((item) => {
          business_purchase_unitprice_detail.push({
            Purchase_Unit_Price_Detail_SerialNumber: "",
            Purchase_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Purchase_Unit_Price: item.Purchase_Unit_Price,
          });
        });
      let business_purchase_unitprice = [
        {
          Purchase_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_purchase_unitprice_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_purchase_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticlePurchasePrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加销售价格单
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加销售价格单");
                  that.submitSales(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("采购价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitSales(business_supplier_article) {
      //添加销售价格单
      const that = this;
      let business_sales_unitprice_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0)
        .forEach((item) => {
          business_sales_unitprice_detail.push({
            Sales_Unit_Price_Detail_SerialNumber: "",
            Sales_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Supplier_SerialNumber: item.Supplier_SerialNumber,
            Unit_Price: item.Sales_Unit_Price,
          });
        });
      let business_sales_unitprice = [
        {
          Sales_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_sales_unitprice_detail,
            business_sales_unitprice_storescope: [
              {
                Sales_Unit_Price_StoreScope_SerialNumber: "",
                Sales_Unit_Price_SerialNumber: "",
                Store_SerialNumber: "STORE0000000001",
              },
            ],
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_sales_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticleSalesPrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加每日库存
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("销售价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitStock(business_supplier_article) {
      //添加每日库存
      const that = this;
      let business_supplier_article_stock_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Quantity) && i.Quantity > 0)
        .forEach((item) => {
          business_supplier_article_stock_detail.push({
            Supplier_Article_Stock_Detail_SerialNumber: "",
            Supplier_Article_Stock_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Quantity: item.Quantity,
          });
        });
      let business_supplier_article_stock = [
        {
          Supplier_Article_Stock_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_supplier_article_stock_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_supplier_article_stock } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyInventory`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日库存执行单更新失败");
                }
                //添加积分配置
                if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("每日库存单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitPointsConfig(business_supplier_article) {
      //添加积分配置
      const that = this;
      let business_points_detail_config = [];
      business_supplier_article
        .filter(
          (i) =>
            i.Pionts.length > 0 &&
            !isNaN(i.Deduction_Limit) &&
            i.Deduction_Limit > 0
        )
        .forEach((item) => {
          business_points_detail_config.push({
            Points_Detail_Config_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Gift_Point: item.Pionts.some((i) => i == "Gift") ? "0" : "1",
            Sales_Point: item.Pionts.some((i) => i == "Sales") ? "0" : "1",
            Cash_Point: item.Pionts.some((i) => i == "Cash") ? "0" : "1",
            Activit_Point: item.Pionts.some((i) => i == "Activit") ? "0" : "1",
            Deduction_Type: item.Deduction_Type,
            Deduction_Limit: item.Deduction_Limit,
            Combination: "1",
          });
        });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_points_detail_config } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            //插入活动商品
            if (
              business_supplier_article.filter((i) => i.Activity.length > 0)
                .length > 0
            ) {
              that.$message.success("开始插入活动商品");
              that.submitActivityArticle(business_supplier_article);
            } else {
              that.loading = false;
              that.$message.success("提交成功");
              window.history.go(-1);
            }
          } else {
            // that.$message.error("积分配置提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitActivityArticle(business_supplier_article) {
      //插入活动商品
      const that = this;
      let business_activity_article = [];
      business_supplier_article.forEach((item) => {
        item.Activity.filter(
          (i) =>
            i.Activity_SerialNumber &&
            !isNaN(i.Activity_Unit_Price) &&
            i.Activity_Unit_Price > 0
        ).forEach((ite) => {
          business_activity_article.push({
            Activity_Article_SerialNumber: "",
            Activity_SerialNumber: ite.Activity_SerialNumber,
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Article_SerialNumber: "",
            Article_Specifications_SerialNumber:
              item.Article_Specifications_SerialNumber,
            Activity_Unit_Price: ite.Activity_Unit_Price,
          });
        });
      });
      let base_operation_log = [
        generateLog(
          "插入活动商品",
          "平台端操作",
          "business_activity_article",
          JSON.stringify({ Add: { business_activity_article } })
        ),
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Add: { business_activity_article, base_operation_log },
          }),
        },
        success: function (res) {
          if (res.Status === "success") {
            that.$message.success("提交成功");
            window.history.go(-1);
          } else {
            // that.$message.error("插入活动商品提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add_article_specifications() {
      this.business_article_group[0].Children.business_article_group_detail.push(
        {
          id: createUniqueString(),
          Specification_Group_Detail_Name: "",
        }
      );
      this.business_article_specifications.push({
        Specifications_Name: "",
        Unit_Price: "", //吊牌价
        SKU_Quantity: "", //SKU数量
        Size: "",
      });
      this.$forceUpdate();
    },
    remove_article_specifications() {
      //删除规格
      if (
        this.business_article_group[0].Children.business_article_group_detail
          .length > 1
      ) {
        this.business_article_group[0].Children.business_article_group_detail.pop();
        this.business_article_specifications.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
      // if (this.form.Children.business_article_specifications.length > 1) {
      //     this.form.Children.business_article_specifications.pop();
      // } else {
      //     this.$message({
      //         message: '不能在删除了',
      //         type: 'warning'
      //     })
      // }
    },
    changeSpecificationsName(index) {
      console.log(
        this.business_article_specifications[index].Specifications_Name
      );
      this.business_article_group[0].Children.business_article_group_detail[
        index
      ].Specification_Group_Detail_Name =
        this.business_article_specifications[index].Specifications_Name;
      this.$forceUpdate();
    },
    add_Other(obj) {
      obj.Other.push({
        Supplier_SerialNumber: "",
        Sales_Unit_Price: "",
        Purchase_Unit_Price: "",
        Quantity: "",
        Pionts: [],
        Deduction_Type: "1",
        Deduction_Limit: "100",
        Activity: [
          {
            Activity_SerialNumber: "",
            Activity_Unit_Price: "",
          },
        ],
      });
    },
    remove_Other(obj) {
      if (obj.Other.length > 0) {
        obj.Other.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_Activity(obj) {
      obj.Activity.push({
        Activity_SerialNumber: "",
        Activity_Unit_Price: "",
      });
    },
    remove_Activity(obj) {
      if (obj.Activity.length > 0) {
        obj.Activity.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_article_group_detail(item) {
      item.Children.business_article_group_detail.push({
        id: createUniqueString(),
        Specification_Group_Detail_Name: "",
      });
    },
    remove_article_group_detail(id, item) {
      item.Children.business_article_group_detail =
        item.Children.business_article_group_detail.filter((it, i) => i != id);
    },
    handleImgClick(formName) {
      //点击查看图片
      this.$refs[formName][0].showViewer = true;
    },
    RemoveImage(formName, index) {
      //删除图片
      this[formName].splice(index, 1);
    },
    sortable(that, container, element, jsonarray, className, callback) {
      //拖拽class配置
      var $ul = that.$el.querySelector(container);
      $ul.addEventListener("selectstart", function (e) {
        e.preventDefault();
      });
      this[className] = Sortable.create($ul, {
        handle: element,
        draggable: element,
        animation: 150,
        onUpdate: (event) => {
          let newIndex = event.newIndex,
            oldIndex = event.oldIndex;
          ($li = $ul.children[newIndex]), ($oldLi = $ul.children[oldIndex]);
          //先删除移动的节点, 再插入移动的节点到原有节点，还原了移动的操作
          $ul.removeChild($li);
          if (newIndex > oldIndex) {
            $ul.insertBefore($li, $oldLi);
          } else {
            $ul.insertBefore($li, $oldLi.nextSibling);
          }
          //通过改变vue遍历数组移动节点
          let item = jsonarray[oldIndex];
          jsonarray.splice(oldIndex, 1);
          jsonarray.splice(newIndex, 0, item);
          if (callback) callback(newIndex, oldIndex);
        },
      });
      this[className].option("disabled", true);
    },
  },
});
